<template>
	<cu-custom :showBack="false"/>
	<view class="register-box">
		<view class="d-flex flex-row welcome pt-5">
			<view class="d-flex flex-column">
				<view class="font-big mt-3">欢迎使用</view>
				<view class="font-lg">盘锦河蟹商家端平台</view>
			</view>
			<image :src="`${getApp.globalData.baseImgUrl}/image/home/03@2x.png`" style="width: 240rpx; height: 240rpx;" mode=""></image>
		</view>
		<view class="register-form">
			<view class="form-box">
				<view class="uni-form-item uni-column">
					<input class="uni-input border-bottom" type="number" placeholder="请输入手机号" v-model="phoneNumber" />
				</view>
				<view class="uni-form-item uni-column">
					<input class="uni-input border-bottom" password type="text" placeholder="请输入密码"
						v-model="passWord" />
				</view>
				<button @click="submit" class="main-bg-color text-white mt-5 font-md">登录</button>
				<view class="d-flex flex-r j-sb mt-1">
					<text @click="forgotPassWord">忘记密码</text>
					<text class="main-text-color" @click="register">注册账号</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import validate from '@/utils/validate.js'
	import cuCustom from '@/components/common/custom.vue'
	import interceptor from "@/utils/request.js"
	export default {
		components: {
			cuCustom
		},
		data() {
			return {
				phoneNumber: null,
				passWord: null,
				getApp:""
			}
		},
		onShow() {
	
			
		},
		created() {
			this.getApp = getApp()
		},
		methods: {
			submit() {
				let _that = this
				// 判断手机号码格式是否正确
				let phoneIstrue = validate.validatePhoneNumber(this.phoneNumber)
				if (phoneIstrue) {
					let data = {
						username: this.phoneNumber,
						password: this.passWord
					}
					interceptor.get('/supplier_applet_api.php?act=userLogin',data).then((res) =>{
						if(res.status === 1){
							uni.showToast({
								title: res.msg,
								icon: 'success',
								success() {
									uni.setStorage({
										key: "USER_ID",
										data: res.info.user_id,
										success() {
											uni.setStorage({
												key: "supplier_id",
												data: res.info.supplier_id,
												success() {
													uni.setStorage({
														key: "USER_Mobile_Number",
														data: _that.phoneNumber
													})
													uni.switchTab({
														url: "/pages/index/index"
													})
												}
											})
											
										}
									})
									
								}
							});
							
						}else if(res.status === 2){
							uni.showToast({
								title: res.msg,
								icon: 'none',
								success() {
									uni.setStorage({
										key: "USER_ID",
										data: res.info.user_id,
										success() {
											uni.navigateTo({
												url: "../register/settlement"
											})
										}
									})
									
								}
							});
						}else if(res.status === 5){
							uni.showToast({
								title: res.msg,
								icon: 'none',
								success() {
									uni.setStorage({
										key: "USER_ID",
										data: res.info.user_id,
										success() {
											uni.setStorage({
												key: "supplier_id",
												data: res.info.supplier_id,
												success() {
													uni.navigateTo({
														url:"../register/result"
													})
												}
											})
											
										}
									})
									
									
								}
							});
						}
						else{
							uni.showToast({
								title: res.msg || '服务端失败',
								icon: 'none'
							});
						}
					})
				}

			},
			forgotPassWord() {
				uni.navigateTo({
					url: '/pagesPackage/minePackage/forgotPassword/index'
				})
			},
			register() {
				uni.navigateTo({
					url: "/pagesPackage/minePackage/register/index"
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.register-box {
		background: #fff;
		position: relative;

		.welcome {
			width: 100%;
			height: calc(100vh - 200rpx);
			background: linear-gradient(0deg, #fff, #F4E3E2);
			padding: 50rpx 60rpx 0 60rpx;
			box-sizing: border-box;
			position: absolut
		}

		.register-form {
			width: 100%;
			position: absolute;
			top: 350rpx;
			padding: 0 45rpx;
			box-sizing: border-box;

			.form-box {
				background: rgba(255, 255, 255, .3);
				border-radius: 16rpx;
				padding: 40rpx 30rpx;
				box-sizing: border-box;

				::v-deep .uni-input {
					height: 55rpx;
					border-radius: 10rpx;
					border: 1px solid #DCDCDC;
				}
			}
		}
	}
</style>